<%-- 
    Document   : basket-content
    Created on : May 12, 2011, 2:13:39 PM
    Author     : Stephen Moulton
--%>
<%@page import="pkg_productManagement.Product"%>
<%@page import="pkg_productManagement.ProductDatabaseFunctions"%>
<%@page import="java.util.Vector"%>
<%@page import="java.text.*"%>
<%
    String id = (String) session.getAttribute("login");
    double total = 0;
    DecimalFormat df = new DecimalFormat("#.##");
    //id = Integer.parseInt(session.getAttribute("login"));
    if (id != null) {
        String user = (String)session.getAttribute("user");
       
        Vector itemList = (Vector)session.getAttribute("items");
        
        
        out.println("<div class=\"page-title\">" + user + "'s Basket </div><br/>");

        if(request.getParameter("product_id") != null)
        {
            itemList.add(request.getParameter("product_id"));
            session.setAttribute("items",itemList);
        }
        
        if(!itemList.isEmpty())
        {
            ProductDatabaseFunctions pDF = new ProductDatabaseFunctions();
         %>
            <table border="1px" style="width: 95%;">
                <tbody>
                    <tr>
                    <td>Product ID</td>
                    <td>Name</td>
                    <td>Quantity</td>
                    <td>Price</td>
                </tr>
        <% 
            for(int i = 0; i < itemList.size(); i++)
            {
                Product product = pDF.getProductsByID(Integer.parseInt(itemList.elementAt(i).toString()));
                total += product.getPrice();
        %>
                <tr>
                    <td><%out.println(product.getID());%></td>
                    <td><%out.println(product.getName());%></td>
                    <td>1</td>
                    <td><%out.println(product.getPrice());%></td>
                </tr>
        
        <%
            }
        %>
                </tbody>
        </table>
       <%
        } //Test if vector is emppty
        out.println("<p>Total amount: " + df.format(total) + "</p>");
        session.setAttribute("total", Double.toString(total));
        %>
        <form method= "post" action="checkout.jsp">
           <input type="hidden" name="user" value="<% user.toString(); %>" />
           <input type ="hidden" name ="addaddress" value ="0">
            <input type="submit" value="Checkout" />
        </form>
        
        
        <%
        
    } //end if for logged in
    
    else {
 %>
 <div class="page-sub-title">No basket</div>
    <div class="intro">
        <p>You have to log into your account <a href="index.jsp">HERE</a> to view the basket. 
            If you do not have an account register <a href="register.jsp">HERE.</a></p>
    </div>
 <%
    }
%>




